package com.huishen.edrivenew.net;

import android.content.Context;

import com.huishen.edrivenew.AppContext;
import com.huishen.edrivenew.Constants;
import com.huishen.edrivenew.util.StringUtils;
import com.loopj.android.http.RequestParams;

import org.apache.http.entity.FileEntity;

import java.io.File;

/**
 * @author wu
 * @version 1.0
 * @created 2015/7/4
 */
public class NetApi {



    public static void baseRequest(Context context, JsonResponseHandler handler,
                                   String methodName, RequestParams params) {
        if(params == null) {
            params = new RequestParams();
        }
        params.put("mobileFlag", AppContext.getInstance().getAppId());
        params.put("type", Constants.APP_TYPE);

//        ApiHttpClient.post(context, methodName, params, handler);
        if(handler != null) {
            handler.setContext(context);
        }
        ApiHttpClient.get(context, methodName, params, handler);
    }

    //上传文件
    public static void uploadFile(Context context, JsonResponseHandler handler,
                                  String methodName, File file) {
        
        String url = Constants.API_URL + methodName + 
            "?mobileFlag=" + AppContext.getInstance().getAppId() + "&type=" + Constants.APP_TYPE;

        FileEntity entity = new FileEntity(file, null);
        
        if(handler != null) {
            handler.setContext(context);
        }
        ApiHttpClient.post(context, url, entity, handler);
    }



    //登录 18615702713 304658
    public static void login(Context context, JsonResponseHandler handler,
                             String name, String passWord) {
        RequestParams params = new RequestParams();
        params.put("name", name);
        params.put("password", passWord);

        NetApi.baseRequest(context, handler, Constants.MOBILE_LOGIN, params);
    }

    //注销
    public static void logout() {}

    //手机端密码修改
    public static void changePassWord(Context context, JsonResponseHandler handler,
                                      String name, String oldPwd, String newPwd) {
        RequestParams params = new RequestParams();
        params.put("name", name);
        params.put("password", oldPwd);
        params.put("newPwd1", newPwd);
        params.put("newPwd2", newPwd);
        NetApi.baseRequest(context, handler, Constants.MOBILE_RESETPWD, params);
    }

    //上传头像，返回相对路径
    public static void uploadHead(Context context, JsonResponseHandler handler, File file) {
        NetApi.uploadFile(context, handler, Constants.MOBILE_UPLOADHEAD, file);
    }

    //学员头像修改
    public static void updateStuHead(Context context, JsonResponseHandler handler, File file) {
        NetApi.uploadFile(context, handler, Constants.STUDENT_UPDATESTUHEAD, file);
    }

    //意见反馈
    public static void feedback(Context context, JsonResponseHandler handler, String content) {
        RequestParams params = new RequestParams();
        params.put("content", content);
        NetApi.baseRequest(context, handler, Constants.MOBILE_FEEDBACK, params);
    }

    //获取驾校近7天的约课信息[新模式]
    public static void querySchoolLessonInfoById(Context context, JsonResponseHandler handler) {
        NetApi.baseRequest(context, handler, Constants.student_querySchoolLessonInfoById, null);
    }
    
    ////统计7天是否可预约 [旧]
    public static void queryStuCoachLessonInfo(Context context, JsonResponseHandler handler, 
                                               int cohId) {
        RequestParams params = new RequestParams();
        params.put("cohId", cohId);
        NetApi.baseRequest(context, handler, Constants.student_queryStuCoachLessonInfo, params);
    }
    
    //根据科目获取直营教练信息[新模式]
    public static void queryDirectCoachPage(Context context, JsonResponseHandler handler,
                                           int subject, int page) {
        RequestParams params = new RequestParams();
        params.put("page", page);
        params.put("subject", subject);
        NetApi.baseRequest(context, handler, Constants.student_queryDirectCoachPage, params);
    }

    //获取直营教练课时预约状态[新模式]
    public static void queryCoachlessonTimeStatus(Context context, JsonResponseHandler handler,
                                                  String cohId, String lessonDate) {
        RequestParams params = new RequestParams();
        params.put("cohId", cohId);
        params.put("lessonDate", lessonDate);
        NetApi.baseRequest(context, handler, Constants.student_queryCoachlessonTimeStatus, params);
    }

    //获取学员的教学大纲进度[新模式]
    public static void queryStuTeachOutline(Context context, JsonResponseHandler handler) {
        NetApi.baseRequest(context, handler, Constants.student_queryStuTeachOutline, null);
    }

    // 获取学员信息
    public static void queryStudentInfo(Context context, JsonResponseHandler handler) {
        NetApi.baseRequest(context, handler, Constants.student_queryStudentInfo, null);
    }

    //预约学车点击日历具体某一天 教练约课详情统计
    public static void queryCohLessonInfoCount(Context context, JsonResponseHandler handler,
                                                  String cohId, String lessonDate) {
        RequestParams params = new RequestParams();
        params.put("cohId", cohId);
        params.put("lessonDate", lessonDate);
        NetApi.baseRequest(context, handler, Constants.student_queryCohLessonInfoCount, params);
    }

    //取消预约
    public static void editLesssonInfoStatus(Context context, JsonResponseHandler handler,
                                             int subject, int timeType, String lessonDate) {
        RequestParams params = new RequestParams();
        params.put("subject", subject);
        params.put("timeType", timeType);
        params.put("lessonDate", lessonDate);
        NetApi.baseRequest(context, handler, Constants.student_editLesssonInfoStatus, params);
    }

    //根据约课ID取消培训预约
    public static void updateTrainLessonInfo(Context context, JsonResponseHandler handler,
                                                  int id) {
        RequestParams params = new RequestParams();
        params.put("id", id);
        NetApi.baseRequest(context, handler, Constants.student_updateTrainLessonInfo, params);
    }
    

    //学员预约课程
    public static void addLessonInfo(Context context, JsonResponseHandler handler,
                                                  String cohId, String lessonDate,
                                     int subject, int timeType) {
        RequestParams params = new RequestParams();
        params.put("cohId", cohId);
        params.put("lessonDate", lessonDate);
        params.put("subject", subject);
        params.put("timeType", timeType);
        NetApi.baseRequest(context, handler, Constants.student_addLessonInfo, params);
    }

    //新增学员约课信息[新模式]
    //outline=//教学大纲ID，timeFrame=15:00//时间段，price=//价格，lessonDate=2015-07-03//时间，
    //cohId=，subject=//科目， invalidlessonId=//无效的课程ID，
    public static void addStulessonTime(Context context, JsonResponseHandler handler,
                                                  String cohId, String lessonDate,
                                        String timeFrame,String price,
                                        String subject, String outline, String invalidlessonId) {
        RequestParams params = new RequestParams();
        params.put("cohId", cohId);
        params.put("lessonDate", lessonDate);
        params.put("timeFrame", timeFrame);
        params.put("price", price);
        params.put("subject", subject);
        if(!StringUtils.isEmpty(outline)) {
            params.put("outline", outline);
        }
        if(!StringUtils.isEmpty(invalidlessonId)) {
            params.put("invalidlessonId", invalidlessonId);
        }
        
        NetApi.baseRequest(context, handler, Constants.student_addStulessonTime, params);
    }

    //取消约课信息[新模式]
    public static void updateStulessonTimeSattus(Context context, JsonResponseHandler handler,
                                                  String cohId, String lessonDate,
                                                 String timeFrame, String subject, String price) {
        RequestParams params = new RequestParams();
        params.put("cohId", cohId);
        params.put("lessonDate", lessonDate);
        params.put("timeFrame", timeFrame);
        params.put("subject", subject);
        params.put("price", price);
        NetApi.baseRequest(context, handler, Constants.student_updateStulessonTimeSattus, params);
    }

    //学时统计：学员学时和金额信息 [新模式]
    public static void queryStuMoneyAndTime(Context context, JsonResponseHandler handler) {
        NetApi.baseRequest(context, handler, Constants.student_queryStuMoneyAndTime, null);
    }

    //学时统计：分页查询预约课程以及详情[新模式]
    public static void queryStuLessonAndDetailPage(Context context, JsonResponseHandler handler,
                                                  String page) {
        RequestParams params = new RequestParams();
        params.put("page", page);
        NetApi.baseRequest(context, handler, Constants.student_queryStuLessonAndDetailPage, params);
    }

    //学时统计的培训详情[新模式]
    public static void queryStuTrainDetail(Context context, JsonResponseHandler handler,
                                                  String lessonInfoId) {
        RequestParams params = new RequestParams();
        params.put("lessonInfoId", lessonInfoId);
        NetApi.baseRequest(context, handler, Constants.student_queryStuTrainDetail, params);
    }

    //新增课程评价信息[新模式]
    //lessonId//课程记录ID, service//服务态度分数，teach//教学质量分数，  body //评价内容
    public static void addStuEvalLessonInfo(Context context, JsonResponseHandler handler,
                                            int lessonId, int service, int teach,
                                            String body, int cohId) {
        RequestParams params = new RequestParams();
        params.put("lessonId", lessonId);
        params.put("service", service);
        params.put("teach", teach);
        params.put("body", body);
        params.put("cohId", cohId);
        NetApi.baseRequest(context, handler, Constants.student_addStuEvalLessonInfo, params);
    }

    //学时统计：分页查询预约记录[新模式]
    public static void queryStuTimeListPage(Context context, JsonResponseHandler handler,
                                            int page) {
        RequestParams params = new RequestParams();
        params.put("page", page);
        NetApi.baseRequest(context, handler, Constants.student_queryStuTimeListPage, params);
    }

    //分页查询预约评价数据[新模式]
    public static void queryOrderEvalPage(Context context, JsonResponseHandler handler,
                                                  int page) {
        RequestParams params = new RequestParams();
        params.put("page", page);
        NetApi.baseRequest(context, handler, Constants.student_queryOrderEvalPage, params);
    }

    //学员绑定教练培训日志
    public static void queryStuBindCoachLogInfo(Context context, JsonResponseHandler handler,
                                                  String cohId) {
        RequestParams params = new RequestParams();
        params.put("cohId", cohId);
        NetApi.baseRequest(context, handler, Constants.student_queryStuBindCoachLogInfo, params);
    }
}
